package net.wanho.shop.service.impl;

import net.wanho.shop.po.PermissionApi;
import net.wanho.shop.mapper.PermissionApiMapper;
import net.wanho.shop.service.PermissionApiService;
import org.springframework.stereotype.Service;
import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 权限功能表 服务实现类
 * </p>
 *
 * @author 猛虎王
 * @since 2024-12-24
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class PermissionApiServiceImpl implements PermissionApiService {

    private final PermissionApiMapper permissionApiMapper;

    /**
     * 权限功能表分页查询
     * @param pageNum
     * @param pageSize
     * @param permissionApi
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public PageInfo findPage(int pageNum, int pageSize, PermissionApi permissionApi) {
        if(ObjectUtil.isNull(permissionApi)){
            permissionApi = new PermissionApi();
        }

        // 分页
        PageHelper.startPage(pageNum,pageSize);
        List<PermissionApi> permissionApiList = permissionApiMapper.select(permissionApi);
        return new PageInfo(permissionApiList);
    }

    /**
     * 根据主键查询权限功能表
     * @param id
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public PermissionApi findById(Serializable id) {
        return permissionApiMapper.selectById(id);
    }

    /**
     * 权限功能表新增
     * @param permissionApi
     */
    @Override
    public void add(PermissionApi permissionApi) {
        permissionApiMapper.insert(permissionApi);
    }

    /**
     * 修改权限功能表
     * @param permissionApi
     */
    @Override
    public void modify(PermissionApi permissionApi) {
        permissionApiMapper.update(permissionApi);
    }

    /**
     * 根据主键删除权限功能表
     * @param id
     */
    @Override
    public void removeById(Serializable id) {
        if(((String)id).contains(",")){
            permissionApiMapper.deleteByIds(((String)id).split(","));
        }else {
            permissionApiMapper.deleteById(id);
        }
    }
}
